from flask import Flask, render_template
from database_m import db_session, init_db
from models_m import User

app = Flask(__name__)
print(__name__)

@app.route('/list')
def index():
    users = User.query.all()
    return ",".join([u.name for u in users])

@app.route('/one')
def one():
    user = User.query.filter(User.name=='admin').first()
    return user.name + "-" + user.email

@app.route('/add')
def insert():
    u = User('adminm', 'adminm@localhost')
    db_session.add(u)
    db_session.commit()
    return "add ok"

# 自动关闭session
@app.teardown_appcontext
def shutdown_session(exception=None):
    db_session.remove()

if __name__ == "__main__":
    # init_db()
    app.run(debug=True)